
# 安装处理
# 打包安装文件
# 1.EWX_SDK_ROOT 下的文件
# 2.资源文件
# 3.二进制文件
macro(ewx_ext_install)
    set(options WITH_INSTALL_TEST)
    set(oneValueArgs EWX_DEBUG_ROOT)
    set(multiValueArgs)
    cmake_parse_arguments(_args "${options}" "${oneValueArgs}"
                    "${multiValueArgs}" ${ARGN} )

    IF(NOT EXISTS ${EWX_SDK_ROOT})
        message(FATAL_ERROR "No SDK EWX_SDK_ROOT=${EWX_SDK_ROOT}.....")
    endif()  

    # 测试处理
    IF(_args_WITH_INSTALL_TEST)
        # 安装测试
        # install(DIRECTORY ${EWX_SDK_ROOT}/ DESTINATION EWX/ COMPONENT RunTime
        #     FILES_MATCHING 
        #     PATTERN     "*.dll"
        #     PATTERN     "*.exe"
        #     PATTERN     "*.ag"
        #     PATTERN     "*.cmake"
        #     PATTERN     "*.timestamp"   EXCLUDE
        #     PATTERN     ".git"          EXCLUDE
        #     PATTERN     ".gitignore"    EXCLUDE
        #     PATTERN     ".pdb"          EXCLUDE
        #     PATTERN     ".log"          EXCLUDE
        # )
    
        return()
    ENDIF()

    IF(WIN32)
        # 安装SDK文件
        # =============================================================================
        # 此处需要按实际情况对不同的目录下的文件进行处理
        # ===bin===
        install(DIRECTORY ${EWX_SDK_ROOT}/bin/ DESTINATION EWX/bin COMPONENT RunTime
                FILES_MATCHING 
                PATTERN     "*.dll"
                PATTERN     "*.qm"
                PATTERN     "*.conf"
                PATTERN     "*.ini"
                PATTERN     "*.exe"
                PATTERN     "*.ag"
                PATTERN     ".pdb"          EXCLUDE
                PATTERN     ".log"          EXCLUDE
                PATTERN     "qt_app.exe"    EXCLUDE
                PATTERN     "qt_app_utf_8.exe"    EXCLUDE
                PATTERN     "shared_library_target_test_app.exe"    EXCLUDE
                PATTERN     "static_library_target_test_app.exe"    EXCLUDE
                PATTERN     "wkf_link_test.exe"    EXCLUDE
                PATTERN     "core_link_test.exe"    EXCLUDE
                PATTERN     "python"    EXCLUDE
            )
        # ===bin/tools===
        install(DIRECTORY ${EWX_SDK_ROOT}/bin/tools/ 
                DESTINATION EWX/bin/tools COMPONENT RunTime
            )

        # CMakeModules
        install(DIRECTORY ${EWX_SDK_ROOT}/CMakeModules/
            DESTINATION EWX/CMakeModules COMPONENT RunTime
        )

        # ===demos===
        __install_demos_scenarios_root_dir(${EWX_SDK_ROOT}/demos EWX/demos)
        

        # ===devenv===
        install(DIRECTORY ${EWX_SDK_ROOT}/devenv/ 
            DESTINATION EWX/devenv COMPONENT RunTime)
        # ===documentation===
        install(DIRECTORY ${EWX_SDK_ROOT}/documentation/ 
            DESTINATION EWX/documentation COMPONENT RunTime)
        # ===ewx_model===
        install(DIRECTORY ${EWX_SDK_ROOT}/ewx_model/ 
            DESTINATION EWX/ewx_model COMPONENT RunTime)
        # ===include===
        install(DIRECTORY ${EWX_SDK_ROOT}/include/ 
            DESTINATION EWX/include COMPONENT RunTime)
        # ===lib===
        install(DIRECTORY ${EWX_SDK_ROOT}/lib/ 
            DESTINATION EWX/lib COMPONENT RunTime
            PATTERN     "Release"    EXCLUDE)
        # ===moduledata===
        install(DIRECTORY ${EWX_SDK_ROOT}/moduledata/ 
            DESTINATION EWX/moduledata COMPONENT RunTime)
        # ===Scenarios===
        install(DIRECTORY ${EWX_SDK_ROOT}/Scenarios/ 
            DESTINATION EWX/Scenarios COMPONENT RunTime)
        # ===resources===
        install(DIRECTORY ${EWX_SDK_ROOT}/resources/ 
            DESTINATION EWX/resources COMPONENT RunTime
            PATTERN     "*.png"
            PATTERN     "log"    EXCLUDE
            PATTERN     "lib"    EXCLUDE
        )
        # =============================================================================

        # 安装traning
        install(DIRECTORY ${PROJECT_SOURCE_DIR}/training/ 
            DESTINATION EWX/training COMPONENT RunTime
            FILES_MATCHING 
            PATTERN     "*.pdf"
            PATTERN     "*.cmake"
            PATTERN     "*.in"
            PATTERN     "*.user"
            PATTERN     "*.txt"
            PATTERN     "*.hpp"
            PATTERN     "*.cpp"
            PATTERN     "*.ag"
            PATTERN     "*.wmv"
            PATTERN     "*.md"
            PATTERN     "*.py"
            PATTERN     "*.bat"
            PATTERN     "*.m"
            PATTERN     ".dll"          EXCLUDE
            PATTERN     ".vscode"       EXCLUDE
            PATTERN     ".pdb"          EXCLUDE
            PATTERN     ".ilk"          EXCLUDE
            PATTERN     ".log"          EXCLUDE
            PATTERN     ".idea"         EXCLUDE
            PATTERN     "sphinx"        EXCLUDE
            PATTERN     "doxygen"       EXCLUDE
        )

        # 安装Scenario文件
        __install_demos_scenarios_root_dir(${PROJECT_SOURCE_DIR}/Scenarios/ EWX/Scenarios)


        # 安装发布文件
        # 通过python脚本和配置文件安装 git submodule docs下的文件
        # 调用脚本需要一些外部变量来决定打包文件的模式
        #   安装模式作为参数：Dev/User/Trail
        #   安装的目标目录

        # 其它文件的安装

    endif()
endmacro()

# 此宏用于安装场景的文件
# 要对安装的文件进行筛选处理，去掉不需要安装的文件
macro(__install_demos_scenarios_root_dir dirpath dstpath)
    install(DIRECTORY ${dirpath}/ DESTINATION ${dstpath} COMPONENT RunTime
        FILES_MATCHING 
        PATTERN     "*.txt"
        PATTERN     "*.rst"
        PATTERN     "*.png"
        PATTERN     "*.md"
        PATTERN     "*.fxw"
        PATTERN     "*.m"
        PATTERN     "*.pl"
        PATTERN     "*.ant"
        PATTERN     "*.dat"
        PATTERN     "*.FXW"
        PATTERN     "*.pdf"
        PATTERN     "*.jpg"
        PATTERN     "*.earth"
        PATTERN     "MIND"
        PATTERN     "*.vcd"
        PATTERN     "psam"
        PATTERN     "*.docx"
        PATTERN     "*.json"
        PATTERN     "*.wav"
        PATTERN     "*.csv"
        PATTERN     "*.cvg"
        PATTERN     "*.ini"
        PATTERN     "*.dt0"
        PATTERN     "*.dt1"
        PATTERN     "*.dt2"
        PATTERN     "*.gnu"
        PATTERN     "*.tspi"
        PATTERN     "*.imesh"
        PATTERN     "*.sep"
        PATTERN     "*.cmd"
        PATTERN     "output"        EXCLUDE
        PATTERN     ".aer"          EXCLUDE
        PATTERN     "old.*.old"          EXCLUDE
        PATTERN     ".evt"          EXCLUDE
        PATTERN     ".log"          EXCLUDE
        PATTERN     ".1"          EXCLUDE
        PATTERN     "waypoint.conf"          EXCLUDE
        PATTERN     "*.bat"          EXCLUDE
        PATTERN     "*.ide_conf"          EXCLUDE
        PATTERN     "*.bgr"          EXCLUDE
        PATTERN     "*.bgt"          EXCLUDE
        PATTERN     "*.def"          EXCLUDE
        PATTERN     "*.fgr"          EXCLUDE
        PATTERN     "*.fgt"          EXCLUDE
        PATTERN     "*.bda"          EXCLUDE
        PATTERN     "*.bdi"          EXCLUDE
        PATTERN     "*.pla"          EXCLUDE
        PATTERN     "*.pli"          EXCLUDE
    )
endmacro(__install_demos_scenarios_root_dir dirpath)
